/*
 * Copyright (c) 2024-2025 LTC-CN. All rights reserved.
 * <p>
 * This file is part of the ltc-cn-springboot project.
 * <p>
 * ltc-cn-springboot is distributed under the terms of the MIT License.
 * For details, see the accompanying LICENSE file or visit:
 * <a href="https://www.ltc-cn.top/projects">...</a>
 */

package top.ltc_cn.springboot_tools.enums;

import java.util.Map;

/**
 * @author ltc-cn xiaoyangcc
 */
public enum LtcResultEnum {
    SUCCESS(200, "成功"),
    FAILED(201, "失败"),
    ERROR(202, "错误"),
    NOT_FOUND(404, "未找到"),
    UNAUTHORIZED(401, "未授权"),
    FORBIDDEN(403, "禁止访问"),
    BAD_REQUEST(400, "请求错误"),
    NOT_IMPLEMENTED(501, "未实现"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    GATEWAY_TIMEOUT(504, "网关超时"),
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    TENCENT_CLOUD_CAPTCHA_NEED(250, "需要防水码")
    ;
    private Integer code;
    private String msg;
    private Object data;

    // Get方法
    public Integer getCode() {
        return code;
    }
    public String getMsg() {
        return msg;
    }
    public Object getData() {
        return data;
    }

    LtcResultEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    LtcResultEnum(Integer code, String msg, Map<String, Object> data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 根据code获取枚举
     * @return LtcResultEnum
     */
    public static LtcResultEnum getByCode(Integer code) {
        for (LtcResultEnum value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return SERVICE_UNAVAILABLE;
    }

    /**
     * 根据枚举获取code
     */
    public static Integer getCodeByEnum(LtcResultEnum ltcResultEnum) {
        return ltcResultEnum.getCode();
    }
}
